package com.qfedu.provider.listener;

import com.qfedu.config.RocketmqConfig;
import com.qfedu.provider.aigc.AigcUtil;
import com.qfedu.provider.entity.DbVideo;
import com.qfedu.provider.mapper.DbVideoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Date;

@Component
@RequiredArgsConstructor
@RocketMQMessageListener(topic = RocketmqConfig.TOPIC_CONTENT, consumerGroup = "zdsminioconsumer")
@Slf4j
public class ContentAuditListener implements RocketMQListener<Integer>{
    private final DbVideoMapper dbVideoMapper;
    private static final String ROLE = "你一名内容审核官，专门审核内容是否合规合法，如果内容涉及到色情、暴力、政治等敏感信息，需要进行反馈，你的回答只有合规和违规，不能出现其他的文字";
        @Override
        public void onMessage(Integer id) {
            DbVideo dbVideo = dbVideoMapper.selectById(id);
//            System.out.println();
//            log.info("aigc------------用户写的内容"+dbVideo.getDescription());
            String result= AigcUtil.createQuestion(ROLE,dbVideo.getDescription());
//            System.out.println("等待审核");
//            System.out.println("aigc返回的结果内容"+result);
            log.info("aigc------------审核的结果为"+result);
            if (StringUtils.hasLength(result)){
                if (result.contains("合规")){
                    dbVideo.setStatus(2);
//                    System.out.println("aigc审核通过");
                    log.info("aigc---------审核通过");
                    dbVideo.setUpdateTime(new Date());
                }else {
                    dbVideo.setStatus(3);
//                    System.out.println("aigc审核不通过");
                    log.info("aigc---------------审核拒绝");
                    dbVideo.setUpdateTime(new Date());
                }
                dbVideoMapper.updateById(dbVideo);
                }
        }

}